package com.lzf.yh.controller;

import com.lzf.yh.commons.JsonBean;
import com.lzf.yh.entity.User;
import com.lzf.yh.userService.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Auther: Wyz
 * @Date: 2021/3/30 20:35
 * @Description:
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("insertUser")
    public JsonBean insertUser(User user){
        return userService.insertUser(user);
    }


    @GetMapping("selectUser")
    public JsonBean selectUser(User user, HttpSession session){
        return userService.selectUser(user,session);
    }

    /**
     * 获得session中的值
     * @param session
     * @return
     */
    @GetMapping("getSession")
    public JsonBean getSession(HttpSession session){
        Object userInfo = session.getAttribute("userInfo");
        if (userInfo!=null){
            return new JsonBean(0,"",userInfo);
        }
        return new JsonBean(0,"",null);
    }

}
